package priv.pront.code.mati.province;

import java.util.*;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-11-11 17:01
 */
public class MC0203_小玛哥的艰难抉择 {

    static class Info {
        private String name;
        private Integer value;
        private Integer time;

        public Integer getTime() {
            return time;
        }

        public void setTime(Integer time) {
            this.time = time;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getValue() {
            return value;
        }

        public void setValue(Integer value) {
            this.value = value;
        }

        public Info(String name, Integer value, Integer time) {
            this.name = name;
            this.value = value;
            this.time = time;
        }
    }

    static List<Info> list = new ArrayList<>();
    static int n;
    static Set<String> set = new HashSet<>();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();

        for (int i = 0; i < n; i++) {
            String s = scanner.next();
            int value = scanner.nextInt();
            if (!set.contains(s)) {
                list.add(new Info(s, value, i));
                set.add(s);
                continue;
            }
            for (Info info : list) {
                String name = info.getName();
                if(name.equals(s)){
                    info.setValue(value + info.getValue());
                    info.setTime(i);
                }
            }
        }

        int score = 10000;
        String flower = "";
        int time = 10000;
        for (Info cur : list) {
            String key = cur.getName();
            Integer value = cur.getValue();
            if (score > value) {
                score = value;
                flower = key;
            }else if(score == value && time > cur.time){
                time = cur.getTime();
                score = value;
                flower = key;
            }
        }

        System.out.println(flower);
        System.out.println(1000 + score);
    }
}
